﻿namespace WMS6.Web.Configuration
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoServiceRef;
    using WMS6.Web.CommonMethodServiceRef;

    public class Location : BasePage
    {
        protected Button btnCopy;
        protected Button btnCreatedLocation;
        protected Button btnDelete;
        protected Button btnGoBack;
        protected Button btnNew;
        protected Button btnSave;
        protected CheckBox chkIsActive;
        protected CheckBox chkIsLoseID;
        protected CheckBox chkIsMultiLot;
        protected CheckBox chkIsMultiSKU;
        protected CheckBox chkSysCreated;
        protected DropDownList ddlABC;
        protected DropDownList ddlLocCategory;
        protected DropDownList ddlLocFlag;
        protected DropDownList ddlLocHandling;
        protected DropDownList ddlLocUsage;
        protected HtmlForm F2151;
        protected HtmlInputHidden hdnField1Type;
        protected HtmlInputHidden hdnField2Type;
        protected HtmlInputHidden hdnField3Type;
        protected HtmlInputHidden hdnField4Type;
        protected HtmlInputHidden hdnField5Type;
        protected HtmlInputHidden hdnFrom;
        protected Label lblABC;
        protected Label lblCheckDig;
        protected Label lblCubicCapacity;
        protected Label lblEndLocation;
        protected Label lblField1Desc;
        protected Label lblField1Example;
        protected Label lblField2Desc;
        protected Label lblField2Example;
        protected Label lblField3Desc;
        protected Label lblField3Example;
        protected Label lblField4Desc;
        protected Label lblField4Example;
        protected Label lblField5Desc;
        protected Label lblField5Example;
        protected Label lblFootPrint;
        protected Label lblHeight;
        protected Label lblIncremental;
        protected Label lblLength;
        protected Label lblLoc;
        protected Label lblLocation;
        protected Label lblLocCategory;
        protected Label lblLocFlag;
        protected Label lblLocHandling;
        protected Label lblLocLevel;
        protected Label lblLocTemplate;
        protected Label lblLocUsage;
        protected Label lblLogicalLoc;
        protected Label lblMsg;
        protected Label lblSeperatorChar_E1;
        protected Label lblSeperatorChar_E2;
        protected Label lblSeperatorChar_E3;
        protected Label lblSeperatorChar_E4;
        protected Label lblSeperatorChar_F1;
        protected Label lblSeperatorChar_F2;
        protected Label lblSeperatorChar_F3;
        protected Label lblSeperatorChar_F4;
        protected Label lblSeperatorChar_I1;
        protected Label lblSeperatorChar_I2;
        protected Label lblSeperatorChar_I3;
        protected Label lblSeperatorChar_I4;
        protected Label lblSeperatorChar_S1;
        protected Label lblSeperatorChar_S2;
        protected Label lblSeperatorChar_S3;
        protected Label lblSeperatorChar_S4;
        protected Label lblStackLimit;
        protected Label lblStartLocation;
        protected Label lblStatus;
        protected Label lblWeightCapacity;
        protected Label lblWidth;
        protected Label lblXCoord;
        protected Label lblYCoord;
        protected Label lblZoneID;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected ScriptManager ScriptManager1;
        public string[] Strarray;
        protected TextBox txtCheckDig;
        protected TextBox txtCubicCapacity;
        protected TextBox txtEnd1Number;
        protected TextBox txtEnd2Number;
        protected TextBox txtEnd3Number;
        protected TextBox txtEnd4Number;
        protected TextBox txtEnd5Number;
        protected TextBox txtFootPrint;
        protected TextBox txtHeight;
        protected TextBox txtIncremental1;
        protected TextBox txtIncremental2;
        protected TextBox txtIncremental3;
        protected TextBox txtIncremental4;
        protected TextBox txtIncremental5;
        protected TextBox txtLength;
        protected TextBox txtLoc;
        protected TextBox txtLocLevel;
        protected TextBox txtLocTemplateID;
        protected TextBox txtLogicalLoc;
        protected TextBox txtStackLimit;
        protected TextBox txtStatr1Number;
        protected TextBox txtStatr2Number;
        protected TextBox txtStatr3Number;
        protected TextBox txtStatr4Number;
        protected TextBox txtStatr5Number;
        protected TextBox txtStatus;
        protected TextBox txtWeightCapacity;
        protected TextBox txtWidth;
        protected TextBox txtXCoord;
        protected TextBox txtYCoord;
        protected TextBox txtZoneID;
        protected UpdatePanel up1;

        protected void btnCopy_Click(object sender, EventArgs e)
        {
            this.txtLoc.Text = "";
            this.txtLoc.Enabled = true;
            this.chkSysCreated.Checked = false;
            base.DataEntityViewState = null;
        }

        protected void btnCreatedLocation_Click(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(this.txtZoneID.Text))
                {
                    if (this.txtStatr1Number.Text.Length != this.txtStatr1Number.MaxLength)
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F2330_005");
                        this.txtStatr1Number.Focus();
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                    }
                    else if (!this.DataValidate(this.txtStatr1Number.Text, this.txtEnd1Number.Text, this.txtStatr1Number.ToolTip))
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F2330_006");
                        this.txtStatr1Number.Focus();
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                    }
                    else if (this.txtEnd1Number.Text.Length != this.txtEnd1Number.MaxLength)
                    {
                        this.lblMsg.Text = base.GetGlobalMsgResource("F2330_005");
                        this.txtEnd1Number.Focus();
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                    }
                    else
                    {
                        if (this.txtStatr2Number.Visible)
                        {
                            if (this.txtStatr2Number.Text.Length != this.txtStatr2Number.MaxLength)
                            {
                                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_005");
                                this.txtStatr2Number.Focus();
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                                return;
                            }
                            if (!this.DataValidate(this.txtStatr2Number.Text, this.txtEnd2Number.Text, this.txtStatr2Number.ToolTip))
                            {
                                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_007");
                                this.txtStatr2Number.Focus();
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                                return;
                            }
                            if (this.txtEnd2Number.Text.Length != this.txtEnd2Number.MaxLength)
                            {
                                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_005");
                                this.txtEnd2Number.Focus();
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                                return;
                            }
                        }
                        if (this.txtStatr3Number.Visible)
                        {
                            if (this.txtStatr3Number.Text.Length != this.txtStatr3Number.MaxLength)
                            {
                                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_005");
                                this.txtStatr3Number.Focus();
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                                return;
                            }
                            if (this.txtEnd3Number.Text.Length != this.txtEnd3Number.MaxLength)
                            {
                                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_005");
                                this.txtEnd3Number.Focus();
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                                return;
                            }
                            if (!this.DataValidate(this.txtStatr3Number.Text, this.txtEnd3Number.Text, this.txtStatr3Number.ToolTip))
                            {
                                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_008");
                                this.txtStatr3Number.Focus();
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                                return;
                            }
                        }
                        if (this.txtStatr4Number.Visible)
                        {
                            if (this.txtStatr4Number.Text.Length != this.txtStatr4Number.MaxLength)
                            {
                                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_005");
                                this.txtStatr4Number.Focus();
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                                return;
                            }
                            if (this.txtEnd4Number.Text.Length != this.txtEnd4Number.MaxLength)
                            {
                                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_005");
                                this.txtEnd4Number.Focus();
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                                return;
                            }
                            if (!this.DataValidate(this.txtStatr4Number.Text, this.txtEnd4Number.Text, this.txtStatr4Number.ToolTip))
                            {
                                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_009");
                                this.txtStatr4Number.Focus();
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                                return;
                            }
                        }
                        if (this.txtStatr5Number.Visible)
                        {
                            if (this.txtStatr5Number.Text.Length != this.txtStatr5Number.MaxLength)
                            {
                                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_005");
                                this.txtStatr5Number.Focus();
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                                return;
                            }
                            if (this.txtEnd5Number.Text.Length != this.txtEnd5Number.MaxLength)
                            {
                                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_005");
                                this.txtEnd5Number.Focus();
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                                return;
                            }
                            if (!this.DataValidate(this.txtStatr5Number.Text, this.txtEnd5Number.Text, this.txtStatr5Number.ToolTip))
                            {
                                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_010");
                                this.txtStatr5Number.Focus();
                                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                                return;
                            }
                        }
                        CreatedLocationinfo CreatedLocation = new CreatedLocationinfo();
                        int fieldCount = 0;
                        if (!string.IsNullOrEmpty(this.txtStatr1Number.Text.Trim()))
                        {
                            CreatedLocation.Field1BeginStr = this.txtStatr1Number.Text.Trim().ToUpper();
                            CreatedLocation.Field1EndStr = this.txtEnd1Number.Text.Trim().ToUpper();
                            CreatedLocation.Field1Length = this.txtStatr1Number.Text.Trim().Length;
                            CreatedLocation.Field1Type = this.hdnField1Type.Value;
                            fieldCount++;
                        }
                        if (!string.IsNullOrEmpty(this.txtStatr2Number.Text.Trim()))
                        {
                            CreatedLocation.Field2BeginStr = this.txtStatr2Number.Text.Trim().ToUpper();
                            CreatedLocation.Field2EndStr = this.txtEnd2Number.Text.Trim().ToUpper();
                            CreatedLocation.Field2Length = this.txtStatr2Number.Text.Trim().Length;
                            CreatedLocation.Field2Type = this.hdnField2Type.Value;
                            fieldCount++;
                        }
                        if (!string.IsNullOrEmpty(this.txtStatr3Number.Text.Trim()))
                        {
                            CreatedLocation.Field3BeginStr = this.txtStatr3Number.Text.Trim().ToUpper();
                            CreatedLocation.Field3EndStr = this.txtEnd3Number.Text.Trim().ToUpper();
                            CreatedLocation.Field3Length = this.txtStatr3Number.Text.Trim().Length;
                            CreatedLocation.Field3Type = this.hdnField3Type.Value;
                            fieldCount++;
                        }
                        if (!string.IsNullOrEmpty(this.txtStatr4Number.Text.Trim()))
                        {
                            CreatedLocation.Field4BeginStr = this.txtStatr4Number.Text.Trim().ToUpper();
                            CreatedLocation.Field4EndStr = this.txtEnd4Number.Text.Trim().ToUpper();
                            CreatedLocation.Field4Length = this.txtStatr4Number.Text.Trim().Length;
                            CreatedLocation.Field4Type = this.hdnField4Type.Value;
                            fieldCount++;
                        }
                        if (!string.IsNullOrEmpty(this.txtStatr5Number.Text.Trim()))
                        {
                            CreatedLocation.Field5BeginStr = this.txtStatr5Number.Text.Trim().ToUpper();
                            CreatedLocation.Field5EndStr = this.txtEnd5Number.Text.Trim().ToUpper();
                            CreatedLocation.Field5Length = this.txtStatr5Number.Text.Trim().Length;
                            CreatedLocation.Field5Type = this.hdnField5Type.Value;
                            fieldCount++;
                        }
                        CreatedLocation.LocationLength = fieldCount;
                        if (this.lblSeperatorChar_S1.Visible)
                        {
                            CreatedLocation.SeperatorChar = this.lblSeperatorChar_S1.Text;
                        }
                        else
                        {
                            CreatedLocation.SeperatorChar = "";
                        }
                        WMS6.Web.CommonMethodServiceRef.LocationInfo locationInfo = new WMS6.Web.CommonMethodServiceRef.LocationInfo();
                        locationInfo = this.GetLocationInfo4Form(locationInfo);
                        locationInfo.CreatedBy = base.UserInfo.UserID;
                        string strMsg = string.Empty;
                        strMsg = CommoneMethodServiceClientProxy.GetInstance().CreatedLocation(CreatedLocation, locationInfo);
                        if (string.IsNullOrEmpty(strMsg))
                        {
                            this.lblMsg.Text = this.txtLocTemplateID.Text + base.GetGlobalMsgResource("F2330_011");
                        }
                        else
                        {
                            this.lblMsg.Text = string.Format(base.GetGlobalMsgResource("F2330_012"), this.txtLocTemplateID.Text, strMsg);
                        }
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,2);$.unblockUI();</script>", false);
                    this.lblMsg.Text = base.GetGlobalMsgResource("F2330_013");
                    this.txtZoneID.Focus();
                }
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);$.unblockUI();</script>", false);
                SysLog.GetInstance().LogError(ex);
                this.lblMsg.Text = ex.Message;
                this.lblMsg.Visible = true;
            }
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.chkSysCreated.Checked)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C011");
            }
            else if (!string.IsNullOrEmpty(this.txtLoc.Text.Trim()))
            {
                try
                {
                    List<string> locationID = new List<string> {
                        this.txtLoc.Text.Trim()
                    };
                    this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Delete(locationID, "LOCATION") + base.GetGlobalMsgResource("C006");
                    this.btnSave.Enabled = false;
                    this.btnDelete.Enabled = false;
                    this.btnCopy.Enabled = false;
                    base.DataEntityViewState = null;
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = base.GetGlobalMsgResource("C007") + ex.Message;
                }
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            switch (this.hdnFrom.Value)
            {
                case "query":
                    base.Response.Redirect("LocationQuery.aspx", false);
                    break;

                case "list":
                    base.Response.Redirect("LocationList.aspx?from=edit", false);
                    break;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtLoc.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_001");
            }
            else if (string.IsNullOrEmpty(this.txtZoneID.Text.Trim()))
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_002");
            }
            else if (base.DataEntityViewState != null)
            {
                this.UpdateLocationInfo();
            }
            else
            {
                this.InsertLocationInfo();
            }
        }

        private int ConvertToIntByValue(string value)
        {
            string[] Strarray = new string[] { 
                "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", 
                "D", "H", "I", "G", "K", "M", "L", "N", "O", "P", "Q", "R", "S", "T", "U", "V", 
                "W", "X", "Y", "Z"
             };
            for (int i = 0; Strarray.Length > i; i++)
            {
                if (Strarray[i] == value.ToUpper())
                {
                    return i;
                }
            }
            return 0;
        }

        private void CreateLocation(LocationTemplateInfo locTemplate)
        {
            if (locTemplate != null)
            {
                this.lblStartLocation.Visible = true;
                this.lblEndLocation.Visible = true;
                this.lblIncremental.Visible = true;
                this.btnCreatedLocation.Visible = true;
                if (locTemplate.Field1Length > 0)
                {
                    this.txtStatr1Number.Visible = true;
                    this.txtStatr1Number.MaxLength = locTemplate.Field1Length;
                    this.txtStatr1Number.ToolTip = locTemplate.Field1Type;
                    this.txtStatr1Number.Attributes.Add("onblur", this.FunctionMatchingByFieldType(locTemplate.Field1Type));
                    this.txtEnd1Number.Visible = true;
                    this.txtEnd1Number.MaxLength = locTemplate.Field1Length;
                    this.txtEnd1Number.Attributes.Add("onblur", this.FunctionMatchingByFieldType(locTemplate.Field1Type));
                    this.txtEnd1Number.ToolTip = locTemplate.Field1Type;
                    this.lblField1Desc.Visible = true;
                    this.lblField1Desc.Text = locTemplate.Field1Desc;
                    this.lblField1Example.Visible = true;
                    this.lblField1Example.Text = this.FunctionExampleByFieldType(locTemplate.Field1Type, locTemplate.Field1Length);
                    this.txtIncremental1.Visible = true;
                    this.hdnField1Type.Value = locTemplate.Field1Type;
                    if (locTemplate.Field2Length > 0)
                    {
                        this.lblSeperatorChar_F1.Visible = true;
                        this.lblSeperatorChar_F1.Text = locTemplate.SeperatorChar;
                        this.lblSeperatorChar_S1.Visible = true;
                        this.lblSeperatorChar_S1.Text = locTemplate.SeperatorChar;
                        this.lblSeperatorChar_E1.Visible = true;
                        this.lblSeperatorChar_E1.Text = locTemplate.SeperatorChar;
                        this.lblSeperatorChar_I1.Visible = true;
                        this.lblSeperatorChar_I1.Text = locTemplate.SeperatorChar;
                        this.txtIncremental2.Visible = true;
                        this.txtStatr2Number.Visible = true;
                        this.txtStatr2Number.MaxLength = locTemplate.Field2Length;
                        this.txtStatr2Number.Attributes.Add("onblur", this.FunctionMatchingByFieldType(locTemplate.Field2Type));
                        this.txtStatr2Number.ToolTip = locTemplate.Field2Type;
                        this.txtEnd2Number.Visible = true;
                        this.txtEnd2Number.MaxLength = locTemplate.Field2Length;
                        this.txtEnd2Number.Attributes.Add("onblur", this.FunctionMatchingByFieldType(locTemplate.Field2Type));
                        this.txtEnd2Number.ToolTip = locTemplate.Field2Type;
                        this.lblField2Desc.Visible = true;
                        this.lblField2Desc.Text = locTemplate.Field2Desc;
                        this.lblField2Example.Visible = true;
                        this.lblField2Example.Text = this.FunctionExampleByFieldType(locTemplate.Field2Type, locTemplate.Field2Length);
                        this.hdnField2Type.Value = locTemplate.Field2Type;
                        if (locTemplate.Field3Length > 0)
                        {
                            this.lblSeperatorChar_F2.Visible = true;
                            this.lblSeperatorChar_F2.Text = locTemplate.SeperatorChar;
                            this.lblSeperatorChar_S2.Visible = true;
                            this.lblSeperatorChar_S2.Text = locTemplate.SeperatorChar;
                            this.lblSeperatorChar_E2.Visible = true;
                            this.lblSeperatorChar_E2.Text = locTemplate.SeperatorChar;
                            this.lblSeperatorChar_I2.Visible = true;
                            this.lblSeperatorChar_I2.Text = locTemplate.SeperatorChar;
                            this.txtIncremental3.Visible = true;
                            this.txtStatr3Number.Visible = true;
                            this.txtStatr3Number.MaxLength = locTemplate.Field3Length;
                            this.txtStatr3Number.Attributes.Add("onblur", this.FunctionMatchingByFieldType(locTemplate.Field3Type));
                            this.txtStatr3Number.ToolTip = locTemplate.Field3Type;
                            this.txtEnd3Number.Visible = true;
                            this.txtEnd3Number.MaxLength = locTemplate.Field3Length;
                            this.txtEnd3Number.Attributes.Add("onblur", this.FunctionMatchingByFieldType(locTemplate.Field3Type));
                            this.txtEnd3Number.ToolTip = locTemplate.Field3Type;
                            this.lblField3Desc.Visible = true;
                            this.lblField3Desc.Text = locTemplate.Field3Desc;
                            this.lblField3Example.Visible = true;
                            this.lblField3Example.Text = this.FunctionExampleByFieldType(locTemplate.Field3Type, locTemplate.Field3Length);
                            this.hdnField3Type.Value = locTemplate.Field3Type;
                            if (locTemplate.Field4Length > 0)
                            {
                                this.lblSeperatorChar_F3.Visible = true;
                                this.lblSeperatorChar_F3.Text = locTemplate.SeperatorChar;
                                this.lblSeperatorChar_S3.Visible = true;
                                this.lblSeperatorChar_S3.Text = locTemplate.SeperatorChar;
                                this.lblSeperatorChar_E3.Visible = true;
                                this.lblSeperatorChar_E3.Text = locTemplate.SeperatorChar;
                                this.txtIncremental4.Visible = true;
                                this.txtStatr4Number.Visible = true;
                                this.txtStatr4Number.MaxLength = locTemplate.Field4Length;
                                this.txtStatr4Number.Attributes.Add("onblur", this.FunctionMatchingByFieldType(locTemplate.Field4Type));
                                this.txtStatr4Number.ToolTip = locTemplate.Field4Type;
                                this.txtEnd4Number.Visible = true;
                                this.txtEnd4Number.MaxLength = locTemplate.Field4Length;
                                this.txtEnd4Number.Attributes.Add("onblur", this.FunctionMatchingByFieldType(locTemplate.Field4Type));
                                this.txtEnd4Number.ToolTip = locTemplate.Field4Type;
                                this.lblField4Desc.Visible = true;
                                this.lblField4Desc.Text = locTemplate.Field4Desc;
                                this.lblField4Example.Visible = true;
                                this.lblField4Example.Text = this.FunctionExampleByFieldType(locTemplate.Field4Type, locTemplate.Field4Length);
                                this.hdnField4Type.Value = locTemplate.Field4Type;
                                if (locTemplate.Field5Length > 0)
                                {
                                    this.lblSeperatorChar_F4.Visible = true;
                                    this.lblSeperatorChar_F4.Text = locTemplate.SeperatorChar;
                                    this.lblSeperatorChar_S4.Visible = true;
                                    this.lblSeperatorChar_S4.Text = locTemplate.SeperatorChar;
                                    this.lblSeperatorChar_E4.Visible = true;
                                    this.lblSeperatorChar_E4.Text = locTemplate.SeperatorChar;
                                    this.txtIncremental4.Visible = true;
                                    this.lblSeperatorChar_I4.Text = locTemplate.SeperatorChar;
                                    this.txtIncremental5.Visible = true;
                                    this.txtStatr5Number.Visible = true;
                                    this.txtStatr5Number.MaxLength = locTemplate.Field5Length;
                                    this.txtStatr5Number.Attributes.Add("onblur", this.FunctionMatchingByFieldType(locTemplate.Field5Type));
                                    this.txtStatr5Number.ToolTip = locTemplate.Field5Type;
                                    this.txtEnd5Number.Visible = true;
                                    this.txtEnd5Number.MaxLength = locTemplate.Field5Length;
                                    this.txtEnd5Number.Attributes.Add("onblur", this.FunctionMatchingByFieldType(locTemplate.Field5Type));
                                    this.txtEnd5Number.ToolTip = locTemplate.Field5Type;
                                    this.lblField5Desc.Visible = true;
                                    this.lblField5Desc.Text = locTemplate.Field5Desc;
                                    this.lblField5Example.Visible = true;
                                    this.lblField5Example.Text = this.FunctionExampleByFieldType(locTemplate.Field5Type, locTemplate.Field5Length);
                                    this.hdnField5Type.Value = locTemplate.Field5Type;
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                this.lblMsg.Text = this.txtLocTemplateID.Text + base.GetGlobalMsgResource("F2330_004");
                this.lblMsg.Visible = true;
            }
            ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);</script>", false);
        }

        private bool DataValidate(string txtStart, string txtEnd, string type)
        {
            switch (type.ToUpper())
            {
                case "NUMBER":
                    if (Convert.ToInt32(txtStart) > Convert.ToInt32(txtEnd))
                    {
                        return false;
                    }
                    return true;

                case "ALPHA":
                    for (int i = 0; txtStart.Length > i; i++)
                    {
                        char CS00003 = txtStart[i];
                        CS00003 = txtEnd[i];
                        if (this.ConvertToIntByValue(CS00003.ToString()) > this.ConvertToIntByValue(CS00003.ToString()))
                        {
                            return false;
                        }
                    }
                    return true;
            }
            return false;
        }

        private string FunctionExampleByFieldType(string Type, int length)
        {
            string strValue = string.Empty;
            string Value = string.Empty;
            string CS40001 = Type.ToUpper();
            if (CS40001 != null)
            {
                if (!(CS40001 == "NUMBER"))
                {
                    if (CS40001 == "ALPHA")
                    {
                        Value = "A";
                        goto Label_004F;
                    }
                }
                else
                {
                    Value = "1";
                    goto Label_004F;
                }
            }
            Value = "";
        Label_004F:
            if (!string.IsNullOrEmpty(Value))
            {
                for (int i = 0; length > i; i++)
                {
                    strValue = strValue + Value;
                }
            }
            return strValue;
        }

        private string FunctionMatchingByFieldType(string Type)
        {
            switch (Type.ToUpper())
            {
                case "NUMBER":
                    return "dataVer._Is123(this,'lblMsg')";

                case "ALPHA":
                    return "dataVer._Is123OrABC(this,'lblMsg')";
            }
            return "";
        }

        private WMS6.Web.BaseInfoServiceRef.LocationInfo GetLocationInfo4Form(WMS6.Web.BaseInfoServiceRef.LocationInfo location)
        {
            location.Loc = this.txtLoc.Text.Trim();
            location.LocUsage = this.ddlLocUsage.SelectedValue;
            location.LocCategory = this.ddlLocCategory.SelectedValue;
            location.LocFlag = this.ddlLocFlag.SelectedValue;
            location.LocHandling = this.ddlLocHandling.SelectedValue;
            location.CheckDig = this.txtCheckDig.Text.Trim();
            location.Abc = this.ddlABC.SelectedValue;
            location.Status = this.txtStatus.Text.Trim();
            location.ZoneID = this.txtZoneID.Text.Trim();
            location.LogicalLoc = this.txtLogicalLoc.Text.Trim();
            location.XCoord = Convert.ToInt32(Convert.ToDecimal((this.txtXCoord.Text.Trim() == "") ? "0" : this.txtXCoord.Text.Trim()));
            location.YCoord = Convert.ToInt32(Convert.ToDecimal((this.txtYCoord.Text.Trim() == "") ? "0" : this.txtYCoord.Text.Trim()));
            location.ZCoord = Convert.ToInt32(Convert.ToDecimal((this.txtLocLevel.Text.Trim() == "") ? "0" : this.txtLocLevel.Text.Trim()));
            location.Length = double.Parse((this.txtLength.Text.Trim() == "") ? "0" : this.txtLength.Text.Trim());
            location.Width = double.Parse((this.txtWidth.Text.Trim() == "") ? "0" : this.txtWidth.Text.Trim());
            location.Height = double.Parse((this.txtHeight.Text.Trim() == "") ? "0" : this.txtHeight.Text.Trim());
            location.CubicCapacity = double.Parse((this.txtCubicCapacity.Text.Trim() == "") ? "0" : this.txtCubicCapacity.Text.Trim());
            location.WeightCapacity = double.Parse((this.txtWeightCapacity.Text.Trim() == "") ? "0" : this.txtWeightCapacity.Text.Trim());
            location.StackLimit = Convert.ToInt32(Convert.ToDecimal((this.txtStackLimit.Text.Trim() == "") ? "0" : this.txtStackLimit.Text.Trim()));
            location.FootPrint = Convert.ToInt32(Convert.ToDecimal((this.txtFootPrint.Text.Trim() == "") ? "0" : this.txtFootPrint.Text.Trim()));
            location.IsMultiSku = this.chkIsMultiSKU.Checked ? "Y" : "N";
            location.IsMultiLot = this.chkIsMultiLot.Checked ? "Y" : "N";
            location.IsLoseID = this.chkIsLoseID.Checked ? "Y" : "N";
            location.IsActive = this.chkIsActive.Checked ? "Y" : "N";
            location.SystemCreated = this.chkSysCreated.Checked ? "Y" : "N";
            return location;
        }

        private WMS6.Web.CommonMethodServiceRef.LocationInfo GetLocationInfo4Form(WMS6.Web.CommonMethodServiceRef.LocationInfo location)
        {
            location.LocTemplateID = this.txtLocTemplateID.Text;
            location.LocUsage = this.ddlLocUsage.SelectedValue;
            location.LocCategory = this.ddlLocCategory.SelectedValue;
            location.LocFlag = this.ddlLocFlag.SelectedValue;
            location.LocHandling = this.ddlLocHandling.SelectedValue;
            location.CheckDig = this.txtCheckDig.Text.Trim();
            location.Abc = this.ddlABC.SelectedValue;
            location.Status = this.txtStatus.Text.Trim();
            location.ZoneID = this.txtZoneID.Text.Trim();
            location.LogicalLoc = this.txtLogicalLoc.Text.Trim();
            location.XCoord = Convert.ToInt32(Convert.ToDecimal((this.txtXCoord.Text.Trim() == "") ? "0" : this.txtXCoord.Text.Trim()));
            location.YCoord = Convert.ToInt32(Convert.ToDecimal((this.txtYCoord.Text.Trim() == "") ? "0" : this.txtYCoord.Text.Trim()));
            location.ZCoord = Convert.ToInt32(Convert.ToDecimal((this.txtLocLevel.Text.Trim() == "") ? "0" : this.txtLocLevel.Text.Trim()));
            location.Length = double.Parse((this.txtLength.Text.Trim() == "") ? "0" : this.txtLength.Text.Trim());
            location.Width = double.Parse((this.txtWidth.Text.Trim() == "") ? "0" : this.txtWidth.Text.Trim());
            location.Height = double.Parse((this.txtHeight.Text.Trim() == "") ? "0" : this.txtHeight.Text.Trim());
            location.CubicCapacity = double.Parse((this.txtCubicCapacity.Text.Trim() == "") ? "0" : this.txtCubicCapacity.Text.Trim());
            location.WeightCapacity = double.Parse((this.txtWeightCapacity.Text.Trim() == "") ? "0" : this.txtWeightCapacity.Text.Trim());
            location.StackLimit = Convert.ToInt32(Convert.ToDecimal((this.txtStackLimit.Text.Trim() == "") ? "0" : this.txtStackLimit.Text.Trim()));
            location.FootPrint = Convert.ToInt32(Convert.ToDecimal((this.txtFootPrint.Text.Trim() == "") ? "0" : this.txtFootPrint.Text.Trim()));
            location.IsMultiSku = this.chkIsMultiSKU.Checked ? "Y" : "N";
            location.IsMultiLot = this.chkIsMultiLot.Checked ? "Y" : "N";
            location.IsLoseID = this.chkIsLoseID.Checked ? "Y" : "N";
            location.IsActive = this.chkIsActive.Checked ? "Y" : "N";
            location.SystemCreated = this.chkSysCreated.Checked ? "Y" : "N";
            return location;
        }

        private void InitDropDrowList()
        {
            base.BindData2DDLBySysCode(this.ddlLocUsage, "LocUsage", true);
            base.BindData2DDLBySysCode(this.ddlLocCategory, "LocCategory", true);
            base.BindData2DDLBySysCode(this.ddlLocFlag, "LocFlag", true);
            base.BindData2DDLBySysCode(this.ddlLocHandling, "LocHandling", true);
            base.BindData2DDLBySysCode(this.ddlABC, "ABC", true);
        }

        private void InsertLocationInfo()
        {
            try
            {
                WMS6.Web.BaseInfoServiceRef.LocationInfo locationInfo = new WMS6.Web.BaseInfoServiceRef.LocationInfo();
                locationInfo = this.GetLocationInfo4Form(locationInfo);
                locationInfo.CreatedBy = base.UserInfo.UserID;
                this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Insert(locationInfo, "LOCATION") + base.GetGlobalMsgResource("C004");
                base.DataEntityViewState = locationInfo;
                this.txtLoc.Enabled = false;
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C005") + ex.Message;
            }
        }

        private void LoadData()
        {
            this.InitDropDrowList();
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.SetLocationInfo2Form();
                this.txtLoc.Enabled = false;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]))
            {
                this.hdnFrom.Value = base.Request.QueryString["from"].ToString();
            }
            this.txtStatus.Text = "OK";
        }

        protected void OnTextChanged_txtLocTemplateID(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(this.txtLocTemplateID.Text))
            {
                try
                {
                    LocationTemplateInfo locTemplate = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(this.txtLocTemplateID.Text, "LOCATION_TEMPLATE") as LocationTemplateInfo;
                    this.PageControlSetting();
                    this.CreateLocation(locTemplate);
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = ex.Message;
                    this.lblMsg.Visible = true;
                }
            }
            else
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2330_003");
                this.lblMsg.Visible = true;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void PageControlSetting()
        {
            this.btnCreatedLocation.Visible = false;
            this.lblStartLocation.Visible = false;
            this.txtStatr1Number.Visible = false;
            this.txtStatr2Number.Visible = false;
            this.txtStatr3Number.Visible = false;
            this.txtStatr4Number.Visible = false;
            this.txtStatr5Number.Visible = false;
            this.lblSeperatorChar_S1.Visible = false;
            this.lblSeperatorChar_S2.Visible = false;
            this.lblSeperatorChar_S3.Visible = false;
            this.lblSeperatorChar_S4.Visible = false;
            this.lblEndLocation.Visible = false;
            this.txtEnd1Number.Visible = false;
            this.txtEnd2Number.Visible = false;
            this.txtEnd3Number.Visible = false;
            this.txtEnd4Number.Visible = false;
            this.txtEnd5Number.Visible = false;
            this.lblSeperatorChar_E1.Visible = false;
            this.lblSeperatorChar_E2.Visible = false;
            this.lblSeperatorChar_E3.Visible = false;
            this.lblSeperatorChar_E4.Visible = false;
            this.lblIncremental.Visible = false;
            this.txtIncremental1.Visible = false;
            this.txtIncremental2.Visible = false;
            this.txtIncremental3.Visible = false;
            this.txtIncremental4.Visible = false;
            this.txtIncremental5.Visible = false;
            this.lblSeperatorChar_I1.Visible = false;
            this.lblSeperatorChar_I2.Visible = false;
            this.lblSeperatorChar_I3.Visible = false;
            this.lblSeperatorChar_I4.Visible = false;
            this.lblField1Desc.Visible = false;
            this.lblField2Desc.Visible = false;
            this.lblField3Desc.Visible = false;
            this.lblField4Desc.Visible = false;
            this.lblField5Desc.Visible = false;
            this.lblField1Example.Visible = false;
            this.lblField2Example.Visible = false;
            this.lblField3Example.Visible = false;
            this.lblField4Example.Visible = false;
            this.lblField5Example.Visible = false;
            this.lblSeperatorChar_F1.Visible = false;
            this.lblSeperatorChar_F2.Visible = false;
            this.lblSeperatorChar_F3.Visible = false;
            this.lblSeperatorChar_F4.Visible = false;
        }

        private void SetLocationInfo2Form()
        {
            try
            {
                string locationID = base.Request.QueryString["ID"].ToString();
                WMS6.Web.BaseInfoServiceRef.LocationInfo location = BaseInfoServiceClientProxy.GetInstance().GetInfoByID(locationID, "LOCATION") as WMS6.Web.BaseInfoServiceRef.LocationInfo;
                base.DataEntityViewState = location;
                if (location != null)
                {
                    this.txtLoc.Text = location.Loc;
                    this.ddlLocUsage.SelectedValue = location.LocUsage;
                    this.ddlLocCategory.SelectedValue = location.LocCategory;
                    this.ddlLocFlag.SelectedValue = location.LocFlag;
                    this.ddlLocHandling.SelectedValue = location.LocHandling;
                    this.txtCheckDig.Text = location.CheckDig;
                    this.ddlABC.SelectedValue = location.Abc;
                    this.txtStatus.Text = location.Status;
                    this.txtZoneID.Text = location.ZoneID;
                    this.txtLogicalLoc.Text = location.LogicalLoc;
                    this.txtXCoord.Text = base.GetPreferenceDigit(location.XCoord);
                    this.txtYCoord.Text = base.GetPreferenceDigit(location.YCoord);
                    this.txtLocLevel.Text = base.GetPreferenceDigit(location.ZCoord);
                    this.txtLength.Text = base.GetPreferenceDigit(location.Length);
                    this.txtWidth.Text = base.GetPreferenceDigit(location.Width);
                    this.txtHeight.Text = base.GetPreferenceDigit(location.Height);
                    this.txtCubicCapacity.Text = base.GetPreferenceDigit(location.CubicCapacity);
                    this.txtWeightCapacity.Text = base.GetPreferenceDigit(location.WeightCapacity);
                    this.txtStackLimit.Text = base.GetPreferenceDigit(location.StackLimit);
                    this.txtFootPrint.Text = base.GetPreferenceDigit(location.FootPrint);
                    this.chkIsMultiSKU.Checked = location.IsMultiSku == "Y";
                    this.chkIsMultiLot.Checked = location.IsMultiLot == "Y";
                    this.chkIsLoseID.Checked = location.IsLoseID == "Y";
                    this.chkIsActive.Checked = location.IsActive == "Y";
                    this.chkSysCreated.Checked = location.SystemCreated == "Y";
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
        }

        private void UpdateLocationInfo()
        {
            try
            {
                WMS6.Web.BaseInfoServiceRef.LocationInfo locationInfo = base.DataEntityViewState as WMS6.Web.BaseInfoServiceRef.LocationInfo;
                locationInfo = this.GetLocationInfo4Form(locationInfo);
                locationInfo.UpdatedBy = base.UserInfo.UserID;
                this.lblMsg.Text = BaseInfoServiceClientProxy.GetInstance().Update(locationInfo, "LOCATION") + base.GetGlobalMsgResource("C002");
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("C003") + ex.Message;
            }
        }
    }
}

